<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<input type="hidden" name="selectedid" id="selectedid"/>
<input type="hidden" name="selectedname" id="selectedname"/>
<input type="hidden" id="postParam" value="<s:property value="postParam"/>"/>
<div class="modal-body">
    <div class="row">
        <div class="col-md-12" id="ajax_user_list_row">
            <legend>
                <span class="label  label-warning"> [选择部门]</span>
            </legend>

            <table id="ajax_post_list_table">
            </table>
            <div id="ajax_post_list_page">
            </div>
        </div>
    </div>
</div>
<div class="modal-footer">
	<a href="#ajax!flow.action" class="btn btn-primary" id="dialog-ok">确定</a>
	<button class="btn" data-dismiss="modal" aria-hidden="true">取消</button>
</div>
<script>
    $("#dialog-ok").unbind("click").bind("click",function(){
        var param=$("#postParam").val();
        switch(param){
                    case 'createpost':
                        $("#create_p_selectIds").val($("#selectedid").val());
                        $("#createpost").val($("#selectedname").val());
                        break;
                    case 'readpost':
                        $("#read_p_selectIds").val($("#selectedid").val());
                        $("#readpost").val($("#selectedname").val());
                        break;
                    case 'editpost':
                        $("#edit_p_selectIds").val($("#selectedid").val());
                        $("#editpost").val($("#selectedname").val());
                        break;
                    case 'docReadPost':
                        $("#docRead_p_selectIds").val($("#selectedid").val());
                        $("#docReadPost").val($("#selectedname").val());
                        break;
                }

        gDialog.fClose();

    });
</script>
<script type="text/javascript">
function run_post_jqgrid_function(){
    jQuery("#ajax_post_list_table").jqGrid({
        url:'ajax-config!postGrid.action',
        mtype:"POST",
        datatype: 'json',
        page : 1,
        colNames:['id ', '名称','描述'],
        colModel : [
            {name:'id',index:'id', width:100,sortable:false,fixed:true,hidden:true},
            {name:'name',index:'name', width:150,sortable:false},
            {name:'description',index:'description',width:250,sortable:false},
        ],
        rowNum : 10,
        rowList:[10,20,30],
        pager : '#ajax_post_list_page',
        sortname : 'id',
        sortorder : "asc",
        gridComplete:function(){
            jqGridStyle();
            var param=$("#postParam").val();
            switch(param){
                    case 'createpost':
                        $("#ajax_post_list_table").multiSelect("initValue",{"gridId":"ajax_post_list_table","inputId":"create_p_selectIds","inputName":"createpost"});
                        break;
                    case 'readpost':
                        $("#ajax_post_list_table").multiSelect("initValue",{"gridId":"ajax_post_list_table","inputId":"read_p_selectIds","inputName":"readpost"});
                        break;
                    case 'editpost':
                        $("#ajax_post_list_table").multiSelect("initValue",{"gridId":"ajax_post_list_table","inputId":"edit_p_selectIds","inputName":"editpost"});
                        break;
                    case 'docReadPost':
                        $("#ajax_post_list_table").multiSelect("initValue",{"gridId":"ajax_post_list_table","inputId":"docRead_p_selectIds","inputName":"docReadPost"});
                        break;
            }
            $(".ui-jqgrid-bdiv").css("overflow-x","hidden");

        },
        onSelectRow: function (rowId, status, e) {
            if(status){
                $("#ajax_post_list_table").multiSelect("addValue",{"gridId":"ajax_post_list_table","rowId":rowId});
            } else {
                $("#ajax_post_list_table").multiSelect("delValue",{"gridId":"ajax_post_list_table","rowId":rowId});
            }
        },
	    jsonReader: {
		    root: "dataRows",
			page: "page",
			total: "total",
			records: "records",
			repeatitems : false
		},

		multiselect: true,
        rownumbers:true,
        gridview:true,
        shrinkToFit:true,
        forceFit:true,
        viewrecords: true,
        autowidth: true,
        height : 'auto',
        loadComplete: function() {
        }
    });
    $(window).on('resize.jqGrid', function() {
		jQuery("#ajax_post_list_table").jqGrid('setGridWidth', $("#ajax_post_list_row").width()-10);
	})

    jQuery("#ajax_post_list_table").jqGrid('navGrid', "#ajax_post_list_page", {
		edit : false,
		add : false,
		del : false,
		search:false
	});

	jQuery("#ajax_post_list_table").jqGrid('filterToolbar',{searchOperators : false,stringResult:true});
}

</script>
<script type="text/javascript">
    $(function(){
        run_post_jqgrid_function();
    });
</script>